﻿using System;
using System.Collections.Generic;

using CtpTrader.Logic.Core.Common;
using CtpTrader.Logic.Core.Quote;
using CtpTrader.Logic.Core.Trade;

namespace CtpTrader.Logic.Core.Strategy
{
    public abstract class StrategyBase
    {
        /******************************** 策略接口 ********************************/

        /// <summary>
        /// 策略名称
        /// </summary>
        public string PolicyName { get { return this.GetType().Name; } }

        /// <summary>
        /// 策略中文名称
        /// </summary>
        public abstract string PolicyChineseName { get; }

        /// <summary>
        /// Bar新开事件
        /// </summary>
        public abstract void BarOpen(BarSeries series);

        /// <summary>
        /// Bar完成事件
        /// </summary>
        public abstract void BarClose(BarSeries series);

        /// <summary>
        /// Bar更新事件
        /// </summary>
        public abstract void BarUpdate(BarSeries series);



        /// <summary>
        /// 取得指定持仓单位
        /// </summary>
        /// <param name="account">账户</param>
        /// <param name="series">Bar序列</param>
        /// <param name="directionType">方向</param>
        /// <returns>持仓单位</returns>
        protected PositionUnit GetUnit(Account account, BarSeries series, DirectionType directionType)
        {
            PositionUnit unit = new PositionUnit();

            unit.Strategy       = this.PolicyName;
            unit.Account        = account;
            unit.Instrument     = series.Instrument;
            unit.BarUnit        = series.BarUnit;
            unit.DirectionType  = directionType;

            return unit;
        }
    }
}
